using skeleton;
using System.Collections.Generic;

public class Skeleton : Enemy
{
    Dictionary<StateCode, State> states;
    float attackRange;

    // ========================================================================

    protected override void Awake()
    {
        base.Awake();

        states = new Dictionary<StateCode, State>();
    }

    protected override void Start()
    {
        foreach (var state in GetComponents<State>())
        {
            state.Init(animator, this);
            states.Add(state.state, state);

            if (state.state == StateCode.Attack)
            {
                attackRange = ((AttackState)state).range;
            }
        }

        base.Start();
    }

    // ========================================================================

    public override float GetAttackRange() => attackRange;
    public State GetState(StateCode state) => states[state];
    public void ChangeState(StateCode newState) => stateMachine.Transition(states[newState]);
    public bool TryChangeState(StateCode newState) => stateMachine.TryTransition(states[newState]);
}